<!DOCTYPE html>
<html lang="zh-CN" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fast Layer 表单示例</title>
    <link rel="stylesheet" href="fats/fast.css">
</head>
<body>
    <h1>Fast Layer 表单示例</h1>
    <form class="fast-form" action="" method="post">
        <input type="text" fast-verify="required|username" name="username" placeholder="请输入用户名">
        <input type="password" fast-verify="required|password" name="password" placeholder="请输入密码">
        <input type="password" fast-verify="required|confirm:password" name="confirmPassword" placeholder="请确认密码">
        <button fast-submit="register" type="submit">注册</button>
    </form>

    <script src="fats/fast.js"></script>
    <script>
        var form = fast.form;

        // 监听注册表单提交
        form.on('submit(register)', function(data){
            console.log('注册表单:', data.field);
            return false;
        });

        // 添加密码框的实时验证
        document.querySelector('[name="password"]').addEventListener('input', function() {
            // 当密码变化时，同时验证确认密码
            const confirmElem = document.querySelector('[name="confirmPassword"]');
            if (confirmElem.value) {
                form.validateElement(confirmElem);
            }
        });
    </script>
</body>
</html>